<template>
    <div class="row">
        <div v-for="item in columnList" :key="item.id" class="col-4 mb-4">
            <div class="card h-100 shadow-sm">
                <div class="card-body text-center">
                   <img :src="item.avatar" :alt="item.title" class="rounded-circle border border-lightw-25 my-3">
                   <h5 class="card-title">{{item.title}}</h5>
                   <p class="card-text text-left">{{item.description}}</p>
                   <a href="#" class="btn btn-outline-primary">进入专栏</a>
                </div>
            </div>
        </div>
    </div>
</template>
<script lang="ts">
import { computed, defineComponent, PropType } from 'vue'
import { ColumnProps } from '../store/types.d'
export default defineComponent({
  name: 'ColumnList',
  props: {
    list: {
      // Array是没有类型的，只是一个数组。但希望它是colunmnProps数组，使用PropTypes方法，接受一个泛型，将Array构造函数返回传入的泛型类型
      type: Array as PropType<ColumnProps[]>,
      required: true
    }
  },
  setup (props) {
    const columnList = computed(() => {
      return props.list.map((item) => {
        if (!item.avatar) {
          item.avatar = require('@/assets/logo.png')
        }
        return item
      })
    })
    return {
      columnList
    }
  }
})

</script>
<style lang="scss">
.card-body {
    img {
      width: 50px;
      height: 50px;
    }
}

</style>
